package com.example.order.itheima;


import com.example.order.itheima.annotation.EnableClients;
import com.example.order.itheima.inf.CouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
public class App {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
        CouponController couponController = context.getBean(CouponController.class);
        String result = couponController.getCoupon("1");
        log.info("result={}",result);
    }


    @EnableClients({"com.example.order.itheima.inf"})
    @Configuration
    static class Application {
        @Bean
        public CouponController couponController(){
            return new CouponController();
        }

    }


    static class CouponController {

        @Autowired
        private CouponService couponService;

        public String getCoupon(String id) {
            return couponService.getCoupon(id);
        }
    }
}
